package com.cj.ai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cj.ai.domain.Models;
import com.cj.ai.service.IModelsService;
import com.cj.common.constant.AiConstants;
import com.cj.common.core.redis.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 缓存预热
 * @author cc
 * @date 2024-08-21 21:21
 **/
@Component
public class CacheWarmUpService implements ApplicationRunner {
    @Autowired
    RedisCache redisCache;

    @Autowired
    IModelsService modelsService;
    @Override
    public void run(ApplicationArguments args) throws Exception {

        List<Models> list = modelsService.list(new LambdaQueryWrapper<Models>().eq(Models::getDelFlag, 1));
        for (Models model : list) {
            redisCache.setCacheMapValue(AiConstants.AI_MODEL_NAMES,model.getName(),model);
        }
    }
}
